# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gedit
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=48.2
pkgrel=1
pkgdesc="A text editor for GNOME (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://gedit-technology.github.io/apps/gedit/"
msys2_repository_url='https://gitlab.gnome.org/World/gedit/gedit/'
msys2_references=(
  "cpe: cpe:/a:gnome:gedit"
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-gspell"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libgedit-amtk"
         "${MINGW_PACKAGE_PREFIX}-libgedit-gfls"
         "${MINGW_PACKAGE_PREFIX}-libgedit-gtksourceview"
         "${MINGW_PACKAGE_PREFIX}-libgedit-tepl"
         "${MINGW_PACKAGE_PREFIX}-libpeas"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-python-gobject"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-appstream-glib"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "${MINGW_PACKAGE_PREFIX}-itstool"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-yelp-tools"
             "${MINGW_PACKAGE_PREFIX}-desktop-file-utils"
             "git")
optdepends=("${MINGW_PACKAGE_PREFIX}-gedit-plugins: Additional features")
source=("git+https://gitlab.gnome.org/GNOME/gedit.git#tag=${pkgver}"
        "git+https://gitlab.gnome.org/GNOME/libgd.git"
        "0001-workaround-no-delayed-loading.patch")
sha256sums=('5aec8e65b9e0e5bf0e99233a55080216ec80ba0502212ff96c651dea4631eb08'
            'SKIP'
            '942d8e9435d8c337d96441f46cb7287b5669890e3df319ab5d49fa576d8e8da3')

prepare() {
  cd "${_realname}"

  git submodule init
  git submodule set-url subprojects/libgd "${srcdir}/libgd"
  git -c protocol.file.allow=always submodule update

  # gedit requires delayed loading which isn't supported by meson
  # yet, so move the lib to /bin.
  # https://github.com/mesonbuild/meson/issues/5093
  patch -Np1 -i "${srcdir}"/0001-workaround-no-delayed-loading.patch
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix=${MINGW_PREFIX} \
    --wrap-mode=nodownload \
    --default-library=both \
    --buildtype=plain \
    "../${_realname}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

  install -Dm644 "${srcdir}/${_realname}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
